package com.ruoyi.rei.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.rei.domain.WorkflowRei;
import com.ruoyi.rei.service.IWorkflowReiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 报销Controller
 *
 * @author ruoyi
 * @date 2021-07-13
 */
@RestController
@RequestMapping("/workflow/rei")
public class WorkflowReiController extends BaseController
{
    @Autowired
    private IWorkflowReiService workflowReiService;

    /**
     * 查询报销列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:rei:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkflowRei workflowRei)
    {
        startPage();
        List<WorkflowRei> list = workflowReiService.selectWorkflowReiList(workflowRei);
        return getDataTable(list);
    }

    /**
     * 导出报销列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:rei:export')")
    @Log(title = "报销", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkflowRei workflowRei)
    {
        List<WorkflowRei> list = workflowReiService.selectWorkflowReiList(workflowRei);
        ExcelUtil<WorkflowRei> util = new ExcelUtil<WorkflowRei>(WorkflowRei.class);
        return util.exportExcel(list, "rei");
    }

    /**
     * 获取报销详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:rei:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(workflowReiService.selectWorkflowReiById(id));
    }

    /**
     * 新增报销
     */
    @PreAuthorize("@ss.hasPermi('workflow:rei:add')")
    @Log(title = "报销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkflowRei workflowRei)
    {
        return toAjax(workflowReiService.insertWorkflowRei(workflowRei));
    }

    /**
     * 修改报销
     */
    @PreAuthorize("@ss.hasPermi('workflow:rei:edit')")
    @Log(title = "报销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkflowRei workflowRei)
    {
        return toAjax(workflowReiService.updateWorkflowRei(workflowRei));
    }

    /**
     * 删除报销
     */
    @PreAuthorize("@ss.hasPermi('workflow:rei:remove')")
    @Log(title = "报销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(workflowReiService.deleteWorkflowReiByIds(ids));
    }
}
